package com.zxd.date;

import java.time.Instant;

/**
 * ClassName:MyInstant
 * Package:com.zxd.newdate
 *
 * @Date:2023/9/18 18:24
 * @Author:zxde
 */

/**
 * 时间戳对象
 * 1s = 1000ms 毫秒
 * 1ms  = 1000us 微秒
 * 1us = 1000ns 纳秒
 *
 */
public class MyInstant {
    public static void main(String[] args) {
        //静态方法获取Instant对象
        Instant now = Instant.now();
        //获取从1970-1-1 00：00：00到现在的秒数
        long epochSecond = now.getEpochSecond();
        //不足1s的纳秒数
        int nano = now.getNano();
        //新加100纳秒
        Instant plus100plusNanos = now.plusNanos(100); //plusSecond加秒 plusMillis加毫秒
        Instant plus100minusNanos = now.minusNanos(100);  //减毫秒
        //isAfter，isBefore判断先后，如plus100plusNanos在plus100plusNanos之后返回true
        boolean after = plus100plusNanos.isAfter(plus100plusNanos);
    }
}
